var exec = require('child_process').exec;
var fs = require('fs');
var rd = require('rd');
var json2csv = require('json2csv');
var sdkList = [{sdk: "com.pingplusplus.android.PaymentActivity", name: "银联支付"},
    {sdk: "com.baidu.android.pushservice", name: "百度云推送"}, {sdk: "com.igexin.sdk", name: "个推推送"},
    {sdk: "cn.jpush.android.service", name: "极光推送"}, {sdk: "com.alipay.sdk", name: "支付宝支付"},
    {sdk: "com.yintong", name: "连连支付"}, {sdk: "com.umeng.message", name: "友盟推送"},
    {sdk: "cn.sharesdk", name: "ShareSDK"}, {sdk: "cn.smssdk", name: "短信验证码SDK"},
    {sdk: "com.tencent.android.tpush", name: "腾讯信鸽推送"}, {sdk: "com.baidu.cloudsdk.social", name: "百度社会化分享"},
    {sdk: "com.baidu.wallet", name: "百度钱包"}, {sdk: "com.umeng.socialize", name: "友盟社会化分享"},
    {sdk: "com.tencent.mm.plugin.openapi.Intent", name: "微信支付"},
    {sdk: "com.xiaomi.push.service", name: "小米推送"}, {sdk: "com.huawei.android.push", name: "华为推送"},
    {sdk: "com.bshare", name: "bshare分享"}, {sdk: "com.avos.avoscloud.PushService", name: "LeanCloud推送"},
    {sdk: "com.baidu.mapapi", name: "百度地图"}, {sdk: "com.amap.api", name: "高德地图"},
    {sdk: "com.google.android.maps", name: "谷歌地图"}, {sdk: "com.tencent.tencentmap.mapsdk", name: "腾讯地图"},
    {sdk: "com.mapbar.android", name: "图吧地图"}, {sdk: "com.tencent.sample", name: "腾讯QQ互联平台"},
    {sdk: "com.xiaomi.account.openauth", name: "小米账号登录"}, {sdk: "com.qihoopay.insdk", name: "360登录"},
    {sdk: "com.megvii.facepp", name: "Face++人脸识别"}, {sdk: "com.iflytek.cloud.FaceDetector", name: "讯飞人脸识别"},
    {sdk: "com.iflytek.speech", name: "讯飞开放平台语音识别"}, {sdk: "com.baidu.voicerecognition", name: "百度语音语音识别"},
    {sdk: "com.unisound.client.SpeechConstants", name: "云知声语音识别"}];

var matchingResult = [];
var fields = ["apkFileUrl"];
sdkList.forEach(function (item) {
    fields.push(item.name)
});
var myCars = [];
var index = 0;
var fileArr;

//var child = exec('cd ../node \n ls', function (err, stdout, stderr) {
//    if (err) console.log(err);
//    fileArr = stdout.split("\n");
//    readAllFile("../node/" + fileArr[index]);
//});
//
//function readAllFile(apkFileUrl) {
//    var files = rd.readSync(apkFileUrl);
//    for (var j = 0; j < files.length; j++) {
//        if (!isFIle(files[j])) {
//            continue;
//        }
//    }
//    saveResult(apkFileUrl)
//}
//
//function isFIle(url) {
//    for (var i = 0; i < sdkList.length; i++) {
//        var dataFile = fs.statSync(url);
//        if (dataFile.isFile()) {
//            getFile(url, i)
//        }
//    }
//    return false;
//}
//
//function getFile(url, i) {
//    var data = fs.readFileSync(url);
//    var filter = new RegExp(sdkList[i].sdk, "i");
//
//    if (filter.test(data.toString())) {
//        matchingResult.push(sdkList[i].name);
//    }
//}
//function saveResult(apkFileUrl) {
//    var data = {"apkFileUrl": apkFileUrl};
//    sdkList.forEach(function (item) {
//        if (matchingResult.indexOf(item.name) != -1) {
//            data[item.name] = 1
//        } else {
//            data[item.name] = 0
//        }
//    });
//    myCars.push(data);
//    var csv = json2csv({data: myCars, fields: fields});
//    fs.writeFile("all", csv, function (err) {
//        if (err) return console.error(err);
//        console.log("数据写入成功！");
//        matchingResult = [];
//        if (index < fileArr.length - 1) {
//            index += 1;
//            readAllFile("../node/" + fileArr[index]);
//        }
//    });
//}
